package br.sc.senai.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import br.sc.senai.conexaoBanco.ConexaoMySQL;
import br.sc.senai.model.Funcionario;

public class FuncionarioDAO {
	public Funcionario consultar(Integer idFuncionario) {
		try {
			Statement st = ConexaoMySQL.getConexaoMySQL().createStatement();
			String query = "SELECT * FROM funcionario WHERE idFuncionario = "
					+ idFuncionario + ";";
			ResultSet rs = st.executeQuery(query);
			Funcionario func = new Funcionario();
			while (rs.next()) {
				func = new Funcionario(idFuncionario, rs.getString("nome"),
						rs.getString("cpf"), rs.getString("telefone"),
						rs.getString("email"), rs.getString("endereco"),
						rs.getString("cidade"), rs.getString("cep"),
						rs.getDate("dataCadastro"),
						rs.getInt("status") == 1 ? true : false);
			}
			return func;
		} catch (SQLException e) {
			System.out
					.println("SQL Exception - dao.FuncionarioDAO.consultar()");
			return null;
		}
	}
}
